package com.bdpn.ch05.controller;

import com.bdpn.ch05.pojo.SysUser;
import com.bdpn.ch05.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserController {
    @Resource
    private UserService userService;

//    @RequestMapping(value = "/getUser" , method = RequestMethod.GET)
////    public SysUser getUser(Long usrId){
////        SysUser user = userService.getUser(usrId);
////        return user;
////    }
    @GetMapping(value = "/users")
    private List<SysUser>findAllUsers(){
        List<SysUser>list = userService.findAllUsers();

        return list;
    }
    @GetMapping(value = "/user/{id}")
    public SysUser getUser(@PathVariable("id") Long usrId){
        SysUser user = userService.getUser(usrId);
        return user;
    }

    @PostMapping(value = "/user")
    public void addUser(SysUser user){
        userService.addUser(user);
    }

    @PostMapping(value = "/user")
    public void updateUser(SysUser user){
        userService.updateUser(user);
    }

    @DeleteMapping(value = "/user/{id}")
    public void deleteUser(@PathVariable("id") Long usrId){
        userService.deleteUser(usrId);
    }
}
